//
//  MessageTableViewCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/9/21.
//

import UIKit

class MessageTableViewCell: UITableViewCell {
    var bgView: UIView!
    var titleLab: UILabel!
    var imagView: UIImageView!
    var timeLab: UILabel!
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = Theme.F5Color
        self.selectionStyle = .none
        self.clipsToBounds = true
        self.initUI()
    }
    
    func initUI(){
        
        self.bgView = UIView(frame: CGRect(x: 14, y: 0, width: kScreenWidth - 28, height: 111))
        self.bgView.backgroundColor = .white
        self.bgView.layer.cornerRadius = 4
        self.bgView.clipsToBounds = true
        self.contentView.addSubview(self.bgView)
        
        self.titleLab = UILabel(frame: CGRect(x: 14, y: 14, width: self.bgView.frame.size.width - 96, height: 60))
        self.titleLab.font = UIFont(name: Theme.PingFangSCRegular, size: 14)
        self.titleLab.textColor = Theme.titleLabColor
        self.titleLab.numberOfLines = 3
        self.bgView.addSubview(self.titleLab)
        
        self.imagView = UIImageView(frame: CGRect(x: self.bgView.frame.size.width - 104, y: 14, width: 90, height: 68))
        self.imagView.backgroundColor = Theme.mainColor
        self.bgView.addSubview(self.imagView)
        
        self.timeLab = UILabel(frame: CGRect(x: 14, y: self.titleLab.frame.maxY + 6, width: self.bgView.frame.size.width - 96, height: 20))
        self.timeLab.font = UIFont(name: Theme.PingFangSCRegular, size: 12)
        self.timeLab.textColor = UIColor(hex: 0x939AA8)
        self.bgView.addSubview(self.timeLab)
        
        self.addLayout()
        
        self.titleLab.text = "内容规则描述规则描述规则描述规则描述规则描述规则描述规则描述规则描述规则描述规则描述…"
        self.timeLab.text = "今天10:00"
    }
    
    func addLayout(){
        
        self.bgView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.height.equalTo(111)
            make.bottom.equalTo(0)
        }
        
        self.titleLab.snp.makeConstraints { make in
            make.top.equalTo(14)
            make.left.equalTo(14)
            make.right.equalTo(-132)
            make.height.equalTo(60)
        }
        
        self.imagView.snp.makeConstraints { make in
            make.top.equalTo(14)
            make.right.equalTo(-14)
            make.width.equalTo(90)
            make.height.equalTo(68)
        }
        
        self.timeLab.snp.makeConstraints { make in
            make.top.equalTo(self.titleLab.snp.bottom).offset(6)
            make.left.equalTo(14)
            make.right.equalTo(-96)
            make.height.equalTo(20)
        }
        
    }
    
    
    //setModel
    func setModel(model: MessageListModel){
        self.titleLab.text = model.title ?? ""
        self.imagView.sd_setImage(with: URL(string: model.imgUrl ?? ""))
        self.timeLab.text = XTManageCenter.checkTimes(createDate: model.createdTime ?? "")
        if model.status == 1{
            self.contentView.alpha = 0.4
        }else{
            self.contentView.alpha = 1
        }
        self.updateConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
